/**
* @desc:  日志管理
* @author qiankui
* @date 2023-4-15 15:38:23
*/
<template>
    <div class="page-container h-100">
        <div class="wrapperform m-b-16">
            <div class="searchbox">
                <el-form :inline="true" :model="form" class="demo-form-inline">
                  <el-form-item :label="$t('date')">
                    <el-date-picker
                        class="inputEl"
                        v-model="regDate"
                        type="daterange"
                        format="yyyy-MM-dd"
                        :picker-options="pickerOptions"
                        range-separator="~"
                        :start-placeholder="$t('Start Date')"
                        :end-placeholder="$t('End Date')"
                        align="right">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item class="BlankPlaceholder" label=".">
                    <el-button size="small" type="primary" class="topBtn" @click="onSearch">{{this.i18n.t('Query')}}</el-button>
                    <el-button size="small" type="handle" class="topBtn" @click="resetSearch">{{this.i18n.t('Reset')}}</el-button>
                  </el-form-item>
                </el-form>
            </div>
        </div>

        <div class="table-container table-box globalDiv">
            <BaseGlobalTable :table_config="table_config" @addTableData="addTableData" @delTableData="delTableData" @handelDetail="handelDetail"
                             @handleSelectionChange="handleSelectionChange" @handleEdit="handleEdit" ref="globalTable"></BaseGlobalTable>
        </div>
        <detail ref='detail' :editTableRow='editTableRow' :detailFlag.sync='detailFlag' v-if='detailFlag'></detail>
        <editOrAdd ref='editOrAdd' :editTableRow='editTableRow' :editFlag.sync='editFlag' v-if='editFlag'></editOrAdd>
    </div>
</template>

<script >
    import {logGetlist} from "@/api/rzgl";
    import {deleteDocument} from "@/api/document";
    export default {
        name: "rzgl_index",
        components: {

        },
        props: {},
        data() {
            return {
                regDate: '',
                pickerOptions: {
                    shortcuts: [{
                        // 最近一周
                        text: this.i18n.t('Last week'),
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        // 最近一个月
                        text: this.i18n.t('Last month'),
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        // 最近三个月
                        text: this.i18n.t('Last three months'),
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                sbjxArr:null,
                sbxhArr:null,
                form: {
                    docTypeId:"",
                    deviceModelId:""
                },
                // 数据分析
                table_config: {
                    table_tbody: [

                    ],
                    thead: [
                        { label: "序号", prop: "@id", type: "index", width: "100" },
                        // 时间
                        { label: this.i18n.t('time'), prop: "createTime", type: "", width: "" },
                        // 日志内容
                        { label: this.i18n.t('Log content'), prop: "content", type: "", width: "" },
                        // 操作人
                        { label: this.i18n.t('operator'), prop: "createBy", type: "", width: "" },
                        // 计算机
                        { label: this.i18n.t('computer'), prop: "hostName", type: "", width: "" }
                    ],
                    tableButtonArr: [

                    ],
                    // 列表前面是否需要显示 checkbox 框，如要显示 值写成 true
                    checkbox: false,
                    index: true,
                    showPagination: true, // 翻页器
                    // 请求表格数据的 url ，可直接传入
                    url: 'log/getlist',
                    // 请求表格数据的 方式
                    method: "post",
                    //表格 title 文字
                    tableTitle: false,
                    //是否需要给 th 加 样式boder 如果需要加上addBoderClass 不需要显示空或者不加这个字段配置
                    addBoderClass: "addBoderClass",
                },
                selectRow: [],
                editTableRow: null,
                detailFlag: false,
                editFlag: false,

            };
        },
        computed: {},
        watch: {},
        mounted() {
            this.setTableHeight()
            this.$refs.globalTable.loading_data();
            window.onresize = ()=>{
                this.setTableHeight()
            }
            // this.getJXList()
        },
        methods: {
            setTableHeight(){
                this.$set(this.table_config,'height',window.innerHeight-307)
            },
            resetSearch(){
                this.regDate=""
                this.$refs.globalTable.loading_data()
            },
            onSearch(){
                const params = {
                    pageNumber: this.form.pageNumber,
                    pageSize: this.form.pageSize,
                    orderBy: []
                }
                if(this.regDate){
                    var formatStr="yyyy-MM-dd"
                    params.startTime=new Date(this.regDate[0]).format(formatStr)+' 00:00:00'
                    params.endTime=new Date(this.regDate[1]).format(formatStr)+' 23:59:59'
                }
                console.log(193,this.regDate);
                this.$refs.globalTable.loading_data(params);
            },
            logGetlist(params) {
                logGetlist(params).then(res => {
                    if (res.code == 200) {
                        console.log(490,res);
                        this.listData=res.data.values;
                    }
                })
            },
            sbxhChange(){
                this.onSearch()
            },
            /**
             * @description  搜索查询
             * @param {fromdata}: Object 查询数据
             **/
            handleSearch(fromdata) {
                this.form = fromdata
                this.getTableData();
            },
            // 获取表格数据
            getTableData() {
                this.$nextTick(() => {
                    this.$refs.globalTable.loading_data(this.form);
                });
            },

            /**
             * @description  添加表格
             * @param {row}: Object 点击项数据
             **/
            addTableData() {
                this.editTableRow = null;
                this.editFlag = true;
            },
            /**
             * @param arr:{data} --勾选的数据
             * @return: not
             * 表格勾选回调
             */
            handleSelectionChange(data) {
                this.selectRow = data;
            },
            /**
             * @param arr:{data} --当前行数据
             * @return: not
             * 表格查看的回调
             */
            handelDetail(data) {
                console.log(data);
                this.W.$tips('warning', '未实现');
                // this.$router.push({path:'/home/sybz',query:{id:data.id}})
                // this.detailFlag = true;
                // this.editTableRow = data
            },
            // 表格删除回调
            delTableData(row) {
                console.log(row);
                // 确定要删除吗
                this.W.$myConfirm('warning', this.i18n.t("Are you sure you want to delete it"))
                    .then(async () => {
                        console.log('确认',deleteDocument,row.id);
                        let res = await deleteDocument({ id: row.id });
                        if (res.code == 200) {
                            // 删除成功
                            this.W.$tips("success", this.i18n.t('Successfully deleted'));
                            this.getTableData();
                        }
                    })
                    .catch(() => {
                    });
            },
            //  表格修改回调
            handleEdit(row) {
                this.editFlag = true;
                this.editTableRow = row;
            },
        },
    };
</script>

<style scoped lang="scss">
    ::v-deep .el-col .el-select {
        width: 205px !important;
    }
    ::v-deep .el-form .el-col .el-form-item__content {
        display: inline-block;
    }
    ::v-deep .el-form .el-col .BlankPlaceholder .el-form-item__content {
        position: absolute;
        right: 15px;
    }
    ::v-deep .BlankPlaceholder .el-button {
        margin: 0 10px;
        padding: 8px 25px;
    }
    .right-height {
        height: calc(100% - 36px);
    }
    ::v-deep .content-width .el-form.wrapperform-box .el-form-item {
        width: calc((100% - 100px) / 3);
    }
    .topBtn {
        padding: 9px 20px;
    }
</style>
